package com.ershu.picture.dao;

import java.sql.SQLException;
import java.util.List;

import org.apache.commons.dbutils.QueryRunner;
import org.apache.commons.dbutils.handlers.BeanListHandler;

import com.ershu.picture.domain.Picture;

import cn.itcast.jdbc.TxQueryRunner;

public class PictureDao {
	private QueryRunner qr = new TxQueryRunner();
	/**
	 * 
	 * @param book_id
	 * @return pictureList
	 * 闁俺绻僢ook_id閺屻儲澹橀崚鏉挎禈閻楀洣淇婇幁锟�
	 */
	public List<Picture> findById(String book_id){
		try {
			String sql = " select * from picture where book_id = ?";
			return qr.query(sql, new BeanListHandler<Picture>(Picture.class),book_id);
		} catch (SQLException e) {
			// TODO: handle exception
			throw new RuntimeException(e);
		}
	}
	
	/**
	 * insert all pictures of this book
	 * @param pictureList
	 * @param bookId
	 * @author zwy
	 * @throws Exception 
	 * 瑕佹敼锛宐ookid鏄疨icture鐨勫睘鎬э紝鍙互涓嶄紶鍙傛暟
	 */
	public void insertPictures(String path,String bookId) throws Exception {
		try {
			String sql = "insert into picture (book_id,path,is_cover)values(?,?,?)";
			Object[] params=new String[3]; 
			params[0] = bookId;
			params[1] = path;
			params[2] = 0;
			qr.update(sql, params);
		}catch(SQLException e) {
			throw e;
		}
		
	}
}
